package com.zdx.yswl.http;

import android.os.AsyncTask;

public abstract class KAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {

	public interface TaskDelegate {
		public void faild_TaskDelegate(int taskId, Object object);

		public void success_TaskDelegate(int taskId, Object object);
	}

	public interface TaskOtherDelegate {
		public void onPreExecute_TaskDelegate(int taskId);

		public void onProgressUpdate_TaskDelegate(int taskId, Object... values);
	}

	


	private TaskDelegate delegate;
	public TaskOtherDelegate otherDelegate;
	private int taskId;

	public KAsyncTask(int taskId, TaskDelegate delegate) {
		super();
		this.taskId = taskId;
		this.delegate = delegate;
	}

	@Override
	protected void onPreExecute() {
		if (otherDelegate != null) {
			otherDelegate.onPreExecute_TaskDelegate(taskId);
		}
		super.onPreExecute();
	}

	/**
	 * 该方法在publishProgress方法调用后，UI线程将调用这个方法从而在界面上展示任务单进度情况
	 */
	@Override
	protected void onProgressUpdate(Progress... values) {
		if (otherDelegate != null) {
			otherDelegate.onProgressUpdate_TaskDelegate(taskId, values);
		}
		super.onProgressUpdate(values);
	}


	public void setDelegate(TaskDelegate delegate){
		this.delegate  = delegate;
	}
	public int getTaskId() {
		return taskId;
	}

	public void setTaskId(int taskId) {
		this.taskId = taskId;
	}

	public TaskDelegate getDelegate() {
		return delegate;
	}
}
